﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using Microsoft.Data.ConnectionUI;
namespace KeelKit.Controls
{
    public partial class BuildConnectString : UserControl
    {
        public BuildConnectString()
        {
            InitializeComponent();
        }

        private void btnBuild_Click(object sender, EventArgs e)
        {         
            DataConnectionDialog dcd = new DataConnectionDialog();
            dcd.DataSources.Add( DataSource.SqlDataSource  );
          
            try
            {
                if (DataSource != null)
                {
                    dcd.SetSelectedDataProvider(DataSource, DataProvider);
                }
                dcd.ConnectionString = this.txtCntStr.Text;
            
            }
            catch (Exception)
            {

            }
            DialogResult dr = DialogResult.Cancel  ;
            try
            {  
              dr=  DataConnectionDialog.Show(dcd);
            }
            catch (Exception)
            {

            }
            if (dr == DialogResult.OK)
            {
                this.txtCntStr.Text = dcd.ConnectionString;
                DataSource = dcd.SelectedDataSource;
                DataProvider  = dcd.SelectedDataProvider;
 
            }
        }
        public string ConnectionString
        {
            get { return this.txtCntStr.Text; }
            set { this.txtCntStr.Text = value; }
        }
        public DataSource  DataSource { get; set; }
        public DataProvider DataProvider { get; set; }
    }
}
